import { type } from 'os';
<!--
 * @Author: your name
 * @Date: 2021-05-17 16:49:32
 * @LastEditTime: 2021-05-20 09:23:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\test\print\addSet.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('add')"
        :visible="addVisible"
        width="700px"
        @close="$emit('update:addVisible',false)"
        :close-on-click-modal='false'
        >  
            <baseForm :option='option' v-model="form" ref='child'>
                
            </baseForm>
            <span slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:addVisible',false)">{{$t('cancel')}}</el-button>
                <el-button type="primary" @click="save('form')">{{$t('sure')}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import baseForm from '../../../components/common/baseForm'
export default {
    components: {
        baseForm
    },
    props: {
        addVisible:{
            type:Boolean,
            default:false
        },
        textDataList:{
            type:Array,
            default:()=> []
        },
        inverterTypeList:{
            type:Array,
            default:()=> []
        },
        PartNoAdd:{
            type:String,
            default:''
        }
    },
    data() {
        return {
            form:{}
        };
    },
    computed: {
        option(){
            return {
                columnNum:'1',
                data:[{
                    type:'input',
                    lable:'料号',
                    name:'partNo',
                    value:this.PartNoAdd,
                    rules:[{ required: true, message: '不能为空'}],
                }
                ,{
                    type:'input',
                    lable:'机型',
                    name:'inverterType',
                    rules:[{ required: true, message: '不能为空'}],
                }
               ],
               
            }}
    },
    watch: {

    },
    created() {

    },
    mounted() {

    },
    methods: {
        async save(){
            if(!this.$refs.child.save()){
                this.comm.showMsg(false)
                return
            }
            let res = await this.API.prtsettingSave({
                partNo:this.form.partNo,
                inverterType:this.form.inverterType,
                // inverterType:this.comm.returnCode(this.inverterTypeList,this.form.inverterType),
            })
            if(res.success){
                if(res.object == 0){
                    this.comm.showMsg(true)
                    this.$emit('uploadData',true)
                    this.$emit('update:addVisible',false)
                }else if(res.object == 1){
                    this.comm.showMsg(false,'料号重复')
                }else if(res.object == 2){
                    this.comm.showMsg(false,'程序异常联系管理员！')
                }
            }
        }
    },
};
</script>

<style  lang="less" scoped>

</style>
